
/*************************************************************************
* Copyright (c) 2008, ShenZhen Coship Electronic Ltd Co.
* All rights reserved.
* 
* File Name:		DXSoundPlay.h
* Summary:			Play audio data which fill by Circle buf 
* 
* Current Version:	1.0
* Author(s):
/------------------------------------------------------------------------/
revision			author				reason					date
1.0					Ding Ning			Initialize Version		2008-6-2
/------------------------------------------------------------------------/
*************************************************************************/

#ifndef _DX_SOUND_PLAY_H_
#define _DX_SOUND_PLAY_H_
#pragma once
#include <mmsystem.h>
#include <dsound.h>
#include "../inc/DecBuf.h"
// #include "SysTrace.h"
#include "mystring.h"

#define NUM_REC_NOTIFICATIONS  16

class CDXSoundPlay
{
protected:
	IDirectSound*						m_pDS;					// DirectSound component
	IDirectSoundBuffer*					m_pDSBuf;				// Sound Buffer object
	IDirectSoundNotify*					m_pDSNotify;			// Notification object
	WAVEFORMATEX						m_wfxOutput;			// Wave format of output 

	// some codes from capture audio 
	DSBPOSITIONNOTIFY					m_aPosNotify[NUM_REC_NOTIFICATIONS + 1];	//notify flag array 
	DWORD								m_dwPlayBufSize;		//play loop buffer size 
	DWORD								m_dwNextPlayOffset;		//offset in loop buffer 
	DWORD								m_dwNotifySize;			//notify pos when loop buffer need to emit the event
	CircleBuf*							m_stream_handler;		// caller stream buffer filler
	int									m_audioVolume;
public:
	BOOL								m_bPlaying ; 
	HANDLE								m_hNotifyEvent;			//notify event 
	BOOL					LoadStreamData() ; 
public:
	static ULONG WINAPI		notify_stream_thd(LPVOID data) ; 
protected:
	HRESULT					InitDirectSound(HWND hWnd) ; 
	HRESULT					FreeDirectSound() ; 
	IDirectSoundBuffer*		CreateStreamBuffer(IDirectSound* pDS, WAVEFORMATEX* wfx) ; 
	BOOL					SetWavFormat(WAVEFORMATEX * wfx) ; 
public:
	CDXSoundPlay(void);
	~CDXSoundPlay(void);
	BOOL					Open(HWND hWnd, CircleBuf* stream_handler) ; 
	BOOL					Close() ; 
	BOOL					CtrlStream(BOOL bPlaying) ; 
	void					SetVolume(int audioVolume);
	int						GetVolume();
//	CWaveFile *g_pWaveFile;
};
#endif